package com.ruoyi.system.domain.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.ruoyi.common.core.domain.SysGeographical;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
public class TreeListGeographical implements Serializable {
    private static final long serialVersionUID = 1L;

    private Long id;
    private Long geographicalId;
    private String geographicalCode;
    private String geographicalName;
    private Long parentId;
    private String ancestors;
    private String geographicalFullName;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeListGeographical> children;

    public TreeListGeographical(SysGeographical sysGeographical) {
        this.id = sysGeographical.getGeographicalId();
        this.geographicalId = sysGeographical.getGeographicalId();
        this.geographicalCode = sysGeographical.getGeographicalCode();
        this.geographicalName = sysGeographical.getGeographicalName();
        this.parentId = sysGeographical.getParentId();
        this.ancestors = sysGeographical.getAncestors();
        this.geographicalFullName = sysGeographical.getGeographicalFullName();
        if (sysGeographical.getChildren() != null) {
            this.children = sysGeographical.getChildren().stream().map(TreeListGeographical::new).collect(Collectors.toList());
        }
    }
}
